import numpy as np
import pyarma as pa

# 计算phi1(A)v1+phi2(A)v2+...+phin(A)vn

def phiv(A, vlist):

    vlist.reverse()

    r, c, s = A.n_rows, A.n_cols, len(vlist)

    E = pa.zeros(r + s, c + s)

    E[0:r - 1, 0:c - 1] = A
    
    for i in range(s):
        E[0:r - 1, c + i] = vlist[i]
    
    if s > 1:
        E[r:r+s-1, c:c+s-1] = pa.diagmat(pa.ones(s, s), 1)
    
    return pa.expmat(E)[0:A.n_rows - 1, E.n_cols - 1]
